//
//  ZJHomePopupView.m
//  ShangHaiHuDongApp
//
//  Created by ZJ on 2017/9/25.
//  Copyright © 2017年 刘应平. All rights reserved.
//

#import "ZJHomePopupView.h"
#define TAG  10000
@interface ZJHomePopupView ()
/** 取消 */
@property (nonatomic, strong) UIButton *button;

@end

@implementation ZJHomePopupView

- (instancetype)init
{
    self = [super init];
    if (self) {
        self.frame = [UIScreen mainScreen].bounds;
        [self addSubview:self.button];
        UITapGestureRecognizer *tapGest = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(action_cancel)];
//        [self addGestureRecognizer:tapGest];
    }
    return self;
}

- (void)setupUI_dataArray:(NSArray *)dataArray{
    
    CGFloat space = 12 * [UIScreen zj_screenHScale];
    CGFloat bootm = self.height - 152 * [UIScreen zj_screenHScale];
    for (int i = 1; i <= dataArray.count; i++) {
        UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(self.button.x, bootm, self.button.width, self.button.height)];
        button.backgroundColor = [UIColor whiteColor];
        button.layer.cornerRadius = 4 * [UIScreen zj_screenWScale];
        [button setTitle:dataArray[dataArray.count - i] forState:UIControlStateNormal];
        [button setTitleColor:[UIColor textBlackColor] forState:UIControlStateNormal];
        button.titleLabel.font = [UIFont systemFontOfSize:16 * [UIScreen zj_textFontScale]];
        [button addTarget:self action:@selector(action_button:) forControlEvents:UIControlEventTouchUpInside];
        button.tag = TAG + dataArray.count - i;
        [self addSubview:button];
        
        bootm -= (space + self.button.height);
    }
}



#pragma mark - 点击事件
- (void)action_cancel{
    if (self.delegate) {
        [self.delegate ZJHomePopupViewDelegate_canleClick];
    }
}


- (void)action_button:(UIButton *)sender{
    if (self.delegate) {
        [self.delegate ZJHomePopupViewDelegate_buttonClickWithIndex:sender.tag - TAG];
    }
}

#pragma mark - Setter


#pragma mark - Getters
- (UIButton *)button{
    if (_button == nil){
        _button = [[UIButton alloc] initWithFrame:CGRectMake(14 * [UIScreen zj_screenWScale], self.height - 68 * [UIScreen zj_screenHScale], self.width - 25 * [UIScreen zj_screenWScale], 44 * [UIScreen zj_screenWScale])];
        _button.backgroundColor = [UIColor whiteColor];
        _button.layer.cornerRadius = 4 * [UIScreen zj_screenWScale];
        [_button setTitle:@"取消" forState:UIControlStateNormal];
        [_button setTitleColor:[UIColor textBlackColor] forState:UIControlStateNormal];
        _button.titleLabel.font = [UIFont systemFontOfSize:16 * [UIScreen zj_textFontScale]];
        [_button addTarget:self action:@selector(action_cancel) forControlEvents:UIControlEventTouchUpInside];
    }
    return _button;
}
@end
